<?php

class Parser_Model_Parser
{
    const RESOURCE_NAME='parser';

    /**
     * Parse tag in text
     * Returns number of found entries
     * 
     * @param string $tag
     * @param string $text
     * 
     * @return int
     */
    public function parse($tag,&$text)
    {
        $text=preg_replace('/((?:<(?!(?:h1|h2|h3|h4|h5|h6|a|b|strong))[\w\d]+?>)(?:[^<]*?))('.preg_quote($tag).')((?:[^<]*?)<)/siu','$1<a href="'.Zend_Registry::get('view')->fixUrl('tag/'.$tag).'" title="'.$tag.'">$2</a>$3',$text,1,$count);
        
        //$text=preg_replace('/([\x20])('.preg_quote($tag).')( |\.|<)/siu','$1<a href="'.Zend_Registry::get('view')->fixUrl('tag/'.$tag).'" title="'.$tag.'">$2</a>$3',$text,1,$count);
        
        $text=preg_replace('/([\x20])('.preg_quote($tag).')( |\.|,|<)/siu','$1<strong>$2</strong>$3',$text,3);
        
        return $count;
    }
}

